package com.smartwebx.ha.dal.util;

import java.text.ParseException;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.time.DateUtils;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;

/**
 * Gis 帮助类
 * 
 * @author XX
 * 
 */
public class DateFullProcess {

	/**
	 * 返回一个时间段内每日的日期值
	 * 
	 * @param startDate
	 * @param endDate
	 * @return
	 * @throws ParseException
	 */
	public static Map<Date, Double> returnDateSectStr(Date startDate,
			Date endDate, Integer hour) {
		long deffDay = ((endDate.getTime() - startDate.getTime()) / 3600 / 24 / 1000);
		List<Date> dateRange = Lists.newArrayList();

		for (int i = 0; i <= deffDay; i++) {
			Date nowDate = DateUtils.addHours(DateUtils.addDays(startDate, i),
					hour);
			dateRange.add(nowDate);
		}

		return returnTimeValMap(dateRange);
	}

	public static Map<Date, Double> returnDateSectStr(Date startDate,
			Date endDate) {
		return returnDateSectStr(startDate, endDate, 0);
	}

	/**
	 * 返回一个时间段内，各个小时值的字符
	 * 
	 * @param startTime
	 * @param endTime
	 * @return
	 * @throws ParseException
	 */
	public static Map<Date, Double> returnTimeSectStr(Date startTime,
			Date endTime) {
		long diffHour = ((endTime.getTime() - startTime.getTime()) / 3600 / 1000);
		List<Date> dateRange = Lists.newArrayList();

		for (int i = 0; i <= diffHour; i++) {
			Date nowDate = DateUtils.addHours(startTime, i);
			dateRange.add(nowDate);
		}

		return returnTimeValMap(dateRange);
	}

	/**
	 * 返回以日期的Key
	 * 
	 * @param dateDiffStr
	 * @param type
	 * @return
	 * @throws ParseException
	 */
	private static Map<Date, Double> returnTimeValMap(List<Date> dateRange) {
		Map<Date, Double> timeValMap = Maps.newLinkedHashMap();
		for (Date date : dateRange) {
			timeValMap.put(date, 0d);
		}
		return timeValMap;
	}

}
